export default {
  data () {
    return {
      parkNameListRow: {
        searchParams:{},
        pageNumber:1,
        total: 0,
        theadsInfo: [
          { index: 0, isShow: false, prop: 'reno', text: '序号', width: 68 },
          { index: 1, isShow: false, prop: 'm', text: '停车场', minWidth: 110 }
        ],
        tbodysInfo: []
      },
      parkNameRow:{}
    }
  },
  created () {
    //this.getList();
  },
  methods: {
    getList () {
      this.getReceiptsList(this.searchParams);
    },
    getReceiptsList (aparams) {//查询列表
      let self = this,
          params = {
            page: this.pageNumber,
            rp: this.pageSize
          };
      params = $.extend({}, params, aparams);

      console.log(params);

      if (params.startDate != "" && params.endDate) {
        if (params.reportType == 'day') {
          params['timeFrom'] = params.startDate;
          params['timeTo'] = params.endDate;
        } else {
          params['timeFrom'] = moment(params.startDate, 'YYYY-MM').startOf('month').format('YYYY-MM-DD');
          params['timeTo'] = moment(params.endDate, 'YYYY-MM').endOf('month').format('YYYY-MM-DD');
        }
      } else {
        params['timeFrom'] = "";
        params['timeTo'] = "";
      }

      API.report.GetReceiptsListData(params)
          .then(res => {
            let data = res.data,
                list = data.rows,
                statistics = data.statistics;
            if (statistics) {
              list.unshift(statistics)
            }
            
            self.tbodysInfo = list;
            self.total = data.total;
          }, err => {})
    },
    exportData(){//导出
      let self = this;
      this.showDialog("是否确认导出记录？",[],function(){
        let params = {
        };
        params = $.extend({}, params, self.searchParams);

        if (params.startDate != "" && params.endDate) {
          if (params.reportType == 'day') {
            params['timeFrom'] = params.startDate;
            params['timeTo'] = params.endDate;
          } else {
            params['timeFrom'] = moment(params.startDate, 'YYYY-MM').startOf('month').format('YYYY-MM-DD');
            params['timeTo'] = moment(params.endDate, 'YYYY-MM').endOf('month').format('YYYY-MM-DD');
          }
        } else {
          params['timeFrom'] = "";
          params['timeTo'] = "";
        }
        console.log(params);
        self.toExport('/report/online/exportReceipts.do', params);
      },"温馨提示",function(){
        //取消时不操作
      });
    },
    toOpenParkList(row,modalName){//打开详情
      this.parkNameRow = row;
      this.toOpenModal(modalName);
      this.getParkNameList(row);
    },
    getParkNameList(row){//获取详情列表
      let self = this,
      str = row.parkName;
      if(str != null){
        var list = str.split(','),arr = [];
        list.map((item)=>{
                  return arr.push({m: item});
                });
        self.parkNameListRow.tbodysInfo = arr;
        self.parkNameListRow.total = arr.length;
        return;
      }
      
      var date=row.date,operator=row.operatorName;
      var fromDate=moment(date,'YYYY-MM').startOf('month').format('YYYY-MM-DD');
      var toDate=moment(date,'YYYY-MM').endOf('month').format('YYYY-MM-DD');
      var params = {
        'fromDate':fromDate,'toDate':toDate,
        "operator":operator
      };
      //params = $.extend({}, params, aparams);
      API.report.GetParkNameList(params)
          .then(res => {
            let data = res.data,
                list = data,
                arr = [];
                list.map((item)=>{
                  return arr.push({m: item});
                });
            self.parkNameListRow.tbodysInfo = arr;
            self.parkNameListRow.total = data.total;
            self.parkNameListRow.pageNumber = data.page;
          }, err => {});
    },
    toSearchParkNameList(params){//弹出窗的列表搜索方法
      this.parkNameListRow.pageNumber = 1;
      this.parkNameListRow.searchParams = $.extend({}, params);
      this.getParkNameList(params);
    },
    getParkNamePagination(curPage, pageSize) {
      this.parkNameListRow.pageNumber = curPage;
      this.parkNameListRow.pageSize = pageSize ? pageSize : this.parkNameListRow.pageSize;
      this.getParkNameList(this.parkNameListRow.searchParams);
    },
    // auditOnlineSettleReport(row){//审核
    //   let self = this;
    //   this.showDialog("是否确定要审批该商家的券报表？",[],function(){
    //     API.report.AuditAkeDayReport({"id":row.id}).then(res => {
    //       if(res.status==1){
    //         self.getList();
    //         self.showToast("操作成功",1);
    //       }else{
    //         self.showToast("操作失败",2);
    //       }
    //     }, err =>{});
    //   },"温馨提示",function(){
    //     //取消时不操作
    //   });
    // },
    confirmOnlineReceipts(row){//确认收款
      let self = this;
      this.showDialog("是否确定收款？",[],function(){
        API.report.ConfirmOnlineReceipts({"id":row.id}).then(res => {
          if(res.status==1){
            self.getList();
            self.showToast("操作成功",1);
          }else{
            self.showToast("操作失败",2);
          }
        }, err =>{});
      },"温馨提示",function(){
        //取消时不操作
      });
    },
    filterMultiCheck (selectionArr) {//必须定义获取多列的方法
      let result = [];
        selectionArr.map((item)=>{
          result.push(item.id);
        });
      return result;
    },
    handleSearchChange(item) {
      switch(item.name) {
        case 'reportType': this.changeReportDimension(item); break;
      }
    },
    changeReportDimension (item) {
      let value = item.value,
          ThisSearchItem = this.searchList[1];
      switch (value) {
        case 'day': ThisSearchItem.type = 'datePicker'; ThisSearchItem.pickerType = ''; break;
        case 'month': ThisSearchItem.type = 'datePicker'; ThisSearchItem.pickerType = '';ThisSearchItem.format='yyyy-MM'; break;
        case 'year': ThisSearchItem.type = 'datePicker'; ThisSearchItem.pickerType = 'year'; break;
      }
      ThisSearchItem.value = '';
    }
  }
}